package com.hmkx.app.rest;

import com.hmkx.app.entity.Articles;
import com.hmkx.app.util.cache.MemcacheManager;
import com.hmkx.app.util.cache.RedisUtil;
import com.hmkx.app.util.comon.ErrorCode;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author hht
 * @ClassName SwaggerDemoController
 * @Description Swagger各种使用方法的demo
 * @Date 2018/12/29 11:52
 * @VERSION 1.0
 */
@RestController
@Api(description = "文章相关",tags={"SwaggerDemoAPi演示"})
@RequestMapping(value = "swagger")
public class SwaggerDemoController {

    @Autowired
    private  MemcacheManager memcacheManager;

    @Resource(name="redisUtil")
    private RedisUtil redisUtil;


    //接口需要的参数，可以有多个，这里只写了一个，它的paramType还有path、query、body、form几种，
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "Token", value = "token", dataType = "String", required = true,defaultValue = "123")})
    //接口功能描述
    @ApiOperation(value = "获取一个用户")
    //接口响应信息，这里定义了一个401，当出现401，接口返回的是自定的错误AnimalError的实例。当然可以定义多个。
    @ApiResponses(value = { @ApiResponse(code = 401, message = "请求未通过认证.", response = ErrorCode.class) })
    @RequestMapping(value="/oneMem", method = RequestMethod.GET)
    public Articles oneMem(){
        return new Articles();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "Token", value = "token", dataType = "String", required = true,defaultValue = "123")})
    @ApiOperation(value = "创建一用户")
    @ApiResponses(value = { @ApiResponse(code = 401, message = "请求未通过认证.", response = ErrorCode.class) })
    @RequestMapping(value="/member/{name}", method = RequestMethod.GET)
    public Articles createMem(
            @ApiParam(defaultValue = "张三")//@ApiParam和@RequestParam注解作用效果相同
            @PathVariable("name") String name){
        Articles member = new Articles();
        member.setTitle(name);
        return member;
    }

}
